<?php


namespace app\job;

use think\queue\Job;
/**
 * 示例
 *  $data = [
        'm' => 'app\admin\Job\Test',
        'a' => 'doWork',
        'param' => [
            'name' => '瓦尔纳',
            'work' => 'up'
        ]
    ];
$result = Queue::push('DailyTasks',  $data, 'queueDailyTasks');
;
 */
class DailyTasks extends Base
{
    /**
     * @param $data
     * Desc:
     * User: 苏鹏
     * Date: 2023/9/15
     * Time: 10:25
     * @return true
     * @throws \Exception
     */
    public function doWork($data)
    {
        $a = $data['a'];
        $m = $data['m'];
        try {
            if (!class_exists($m)) {
               //返回错误信息 基类中有记录
                return $m.msg_code(26); //类不存在
            }
            $model = new $m();
            if (!method_exists($model, $a)) {
                return $m.'_'.$a.msg_code(27); //类不存在此方法
            }
            return $model->$a($data['param']);
        } catch (\Exception $e) {
            //记录错误信息
            return $e->getMessage();
        }

        return true;
    }
}